<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">

        <h2>Supplier Rating</h2>
        <h:form id="rateSupplierForm" style="font-size: 85%">
            <br/>
            <p:panel>
                <p:messages/>
                <br/>   
                <h:panelGrid columns="3" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Supplier Id: "/>
                    <h:outputText id="supplierId" value="#{rsManagerBean.supplier.supplierId}"/>
                    <h:outputText value=""/>
                    
                    <h:outputLabel style="font-weight: bold" value="Supplier Name: "/>
                    <p:inputText id="supplierName" value="#{rsManagerBean.supplier.supplierName}" disabled="true"/>
                    <p:commandButton image="ui-icon ui-icon-search" oncomplete="supplierDialog.show()"/>
                    
                    <h:outputLabel style="font-weight: bold" value="Supplier Overall Rating: "/>
                    <h:outputText id="supplierRating" value="#{rsManagerBean.supplier.rating}">
                        <f:convertNumber pattern="#0.00"/>
                    </h:outputText>
                </h:panelGrid>

                <br/>
                <br/>
                <h:panelGroup id="invoices" rendered="#{rsManagerBean.supplier.supplierName != ''}">
                    <br/>
                    <h:outputText value="Goods Receipts" style="font-weight: bold; font-size: 110%"/>
                    <p:separator/>
                    <br/>
                    <p:tabView>
                        
                        <p:tab title="Unrated">
                            
                            <br/>
                            <br/>
                            <p:dataTable var="rec" value="#{rsManagerBean.unratedGoodsReceipt}" paginator="true" rows="10">
                            
                                <p:column headerText="Goods Receipt Id">
                                    <h:outputText value="#{rec.goodsReceiptId}"/>
                                </p:column>
                                
                                <p:column headerText="Goods Receipt Date">
                                    <h:outputText value="#{rec.dateReceipt}">
                                        <f:convertDateTime pattern="MMM dd, yyyy"/>
                                    </h:outputText>
                                </p:column>
                                
                                <p:column headerText="Options">
                                    <p:commandButton image="ui-icon ui-icon-calculator" title="Rate Invoice" action="#{rsManagerBean.rateGoodsReceipt(rec.id)}"/>
                                </p:column>
                            
                            </p:dataTable>
                            <br/>
                            <br/>
                        </p:tab>
                        
                        <p:tab title="Rated">
                            
                            <br/>
                            <br/>
                            <p:dataTable var="rec" value="#{rsManagerBean.ratedGoodsReceipt}" paginator="true" rows="10">
                                
                                <p:column headerText="Goods Receipt Id">
                                    <h:outputText value="#{rec.goodsReceiptId}"/>
                                </p:column>
                                
                                <p:column headerText="Goods Receipt Date">
                                    <h:outputText value="#{rec.dateReceipt}">
                                        <f:convertDateTime pattern="MMM dd, yyyy"/>
                                    </h:outputText>
                                </p:column>
                                
                                <p:column headerText="Goods Receipt Rating">
                                    <h:outputText value="#{rec.rating.overall}">
                                        <f:convertNumber pattern="#.##"/>
                                    </h:outputText>
                                </p:column>
                                
                                <p:column headerText="Options">
                                    <p:commandButton image="ui-icon ui-icon-search"  title="View Rating" action="#{rsManagerBean.rateGoodsReceiptDisplay(rec.id)}"/>
                                </p:column>
                            
                            </p:dataTable>
                            <br/>
                            <br/>
                        </p:tab>
                        
                    </p:tabView>
                    
                </h:panelGroup>
                <br/>
            </p:panel>
            <br/>
        </h:form>
        
        <p:dialog header="Search Supplier" widgetVar="supplierDialog" showEffect="fade" hideEffect="fade" resizable="false" modal="true" width="600">  
            <h:form id="supplierForm">
                <br/>
                <p:dataTable var="supplier" value="#{rsManagerBean.allSupplier}" emptyMessage="No supplier found with given criteria"  selection="#{rsManagerBean.supplier}" selectionMode="single">

                    <p:column filterBy="#{supplier.supplierId}" 
                              headerText="Supplier Id"
                              filterMatchMode="contains">
                        <h:outputText value="#{supplier.supplierId}" />
                    </p:column>

                    <p:column filterBy="#{supplier.supplierName}" 
                              headerText="Supplier Name"
                              filterMatchMode="contains">
                        <h:outputText value="#{supplier.supplierName}" />
                    </p:column>

                </p:dataTable>
                <br/>
                <br/>
                <div align="right">
                    <p:commandButton value="Select Supplier" update="rateSupplierForm" oncomplete="supplierDialog.hide()"/>
                </div>
                <br/>
            </h:form>
        </p:dialog>

    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>